<?php
/********************************************************************
Product    : Plotalot
Date       : 7 August 2011
Copyright  : Les Arbres Design 2010-2011
Contact    : http://extensions.lesarbresdesign.info
Licence    : GNU General Public License
*********************************************************************/

defined('_JEXEC') or die('Restricted Access');

jimport( 'joomla.application.component.view' );

require_once JPATH_COMPONENT.DS.'helpers'.DS.'view_helper.php';

class PlotalotViewChartList extends JView
{
function display($tpl = null)
{
	JToolBarHelper::title(LA_COMPONENT_NAME, 'plotalot.png');
	JToolBarHelper::deleteList();
	JToolBarHelper::unpublishList();
	JToolBarHelper::publishList();
	JToolBarHelper::custom('copy', 'copy.png', 'copy_f2.png', 'COM_PLOTALOT_COPY', true);
	JToolBarHelper::editListX();
	JToolBarHelper::custom('new_chart', 'chart.png', 'chart_f2.png', 'COM_PLOTALOT_NEW_CHART', false);
	JToolBarHelper::custom('new_table', 'table.png', 'table_f2.png', 'COM_PLOTALOT_NEW_TABLE', false);
	JToolBarHelper::custom('new_item',  'item.png',  'item_f2.png',  'COM_PLOTALOT_NEW_ITEM', false);
	JToolBarHelper::preferences(LA_COMPONENT,300,400);
	JToolBarHelper::custom('help', 'help.png', 'help_f2.png', 'COM_PLOTALOT_JHELP', false);

// get the current filter	

	$app = &JFactory::getApplication();
	$filter_state = $app->getUserStateFromRequest(LA_COMPONENT.'.filter_state','filter_state','','word');
	$filter_chart_type = $app->getUserStateFromRequest(LA_COMPONENT.'.filter_chart_type','filter_chart_type',CHART_TYPE_ANY,'int');

// Create the state filter html

	$lists['state']	= JHTML::_('grid.state', $filter_state );

// make the chart type filter

	$chart_types = array(
		CHART_TYPE_ANY         => JText::_('COM_PLOTALOT_CHART_TYPE_ANY'),
		CHART_TYPE_SINGLE_ITEM => JText::_('COM_PLOTALOT_CHART_TYPE_SINGLE_ITEM'),
		CHART_TYPE_TABLE       => JText::_('COM_PLOTALOT_CHART_TYPE_TABLE'),
		CHART_TYPE_LINE        => JText::_('COM_PLOTALOT_CHART_TYPE_LINE'),
		CHART_TYPE_SCATTER     => JText::_('COM_PLOTALOT_CHART_TYPE_SCATTER'),
		CHART_TYPE_BAR         => JText::_('COM_PLOTALOT_CHART_TYPE_BAR'),
		CHART_TYPE_PIE         => JText::_('COM_PLOTALOT_CHART_TYPE_PIE'),
		);

	$lists['chart_type'] = LA_view::make_list('filter_chart_type', $filter_chart_type, $chart_types, CHART_TYPE_ANY, 'onchange="submitform( );"');					

// get the order states				

	$filter_order = $app->getUserStateFromRequest(LA_COMPONENT.'.filter_order', 'filter_order', 'chart_name');
	$filter_order_Dir = $app->getUserStateFromRequest(LA_COMPONENT.'.filter_order_Dir', 'filter_order_Dir', 'asc');
	$lists['order_Dir'] = $filter_order_Dir;
	$lists['order'] = $filter_order;

// get the current Joomla database name

	$config =& JFactory::getConfig();
	$website_database = $config->getValue('config.db');

	$plotalot = new Plotalot;

	?>
	<form action="index.php" method="post" name="adminForm" id="adminForm">

	<input type="hidden" name="option" value="<?php echo LA_COMPONENT ?>" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="controller" value="" />
	<input type="hidden" name="filter_order" value="<?php echo $lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" value="" />
	<?php echo JHTML::_('form.token'); ?>

	<table>
	<tr>
		<td align="left" width="100%">
		</td>
		<td nowrap="nowrap">
			<?php
				echo $lists['chart_type'];
				echo '&nbsp;';
				echo $lists['state'];
			?>
		</td>
	</tr>
	</table>
	<div id="editcell">
		<table class="adminlist">
		<thead>
			<tr>
				<th width="5"><?php echo JHtml::_('grid.sort',  'COM_PLOTALOT_ID', 'id', $lists['order_Dir'], $lists['order']); ?></th>
				<th width="20"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" /></th>			
				<th width="5%" class="title" nowrap="nowrap"><?php echo JText::_('COM_PLOTALOT_JPUBLISHED'); ?></th>
				<th><?php echo JHtml::_('grid.sort',  'COM_PLOTALOT_NAME', 'chart_name', $lists['order_Dir'], $lists['order']); ?></th>
				<th><?php echo JHtml::_('grid.sort',  'COM_PLOTALOT_TYPE', 'chart_type', $lists['order_Dir'], $lists['order']); ?></th>
				<th><?php echo JHtml::_('grid.sort',  'COM_PLOTALOT_DATABASE', 'db_name', $lists['order_Dir'], $lists['order']); ?></th>
			</tr>
		</thead>
		<tfoot>
			<tr>
				<td colspan="9"><?php echo $this->pagination->getListFooter(); ?></td>
			</tr>
		</tfoot>
		<?php
		if ($this->items == null)
			{
			echo '</table></div></form>';
			return;
			}
			
		$k = 0;
		$n = count($this->items);
		for ($i=0; $i < $n; $i++)
			{
			$row = &$this->items[$i];
			$checked 	= JHTML::_('grid.id',   $i, $row->id);
			$link 		= JRoute::_(LA_COMPONENT_LINK.'&task=edit&cid[]='.$row->id);
			$published 	= JHTML::_('grid.published', $row, $i);
			switch ($row->chart_type)
				{
				case CHART_TYPE_TABLE:
					$icon = 'c_table.gif'; break;
				case CHART_TYPE_SINGLE_ITEM:
					$icon = 'c_item.gif'; break;
				case CHART_TYPE_LINE:
					$icon = 'c_line.gif'; break;
				case CHART_TYPE_SCATTER:
					$icon = 'c_scatter.gif'; break;
				case CHART_TYPE_BAR_H_STACK:
				case CHART_TYPE_BAR_H_GROUP:
					$icon = 'c_bar_h.gif'; break;
				case CHART_TYPE_BAR_V_STACK:
				case CHART_TYPE_BAR_V_GROUP:
					$icon = 'c_bar_v.gif'; break;
				case CHART_TYPE_PIE_2D:
				case CHART_TYPE_PIE_2D_V:
					$icon = 'c_pie_2d.gif'; break;
				case CHART_TYPE_PIE_3D:
				case CHART_TYPE_PIE_3D_V:
					$icon = 'c_pie_3d.gif'; break;
				default:
					$icon = '';
				}
			$image_html = JHTML::_('image', ADMIN_ASSETS_URL.$icon,'');
			echo '<tr class="row'.$k.'">';
			echo '<td>'.$row->id.'</td>';
			echo '<td>'.$checked.'</td>';
			echo '<td align="center">'.$published.'</td>';
			echo '<td><a href="'.$link.'">'.$row->chart_name.'</a></td>';
			echo '<td>'.$image_html.' '.$plotalot->chartTypeName($row->chart_type).'</td>';
			if ($row->db_name == '')
				echo '<td>'.JText::_('COM_PLOTALOT_JSITE').' ('.$website_database.')</td>';
			else
				echo '<td>'.$row->db_name.'</td>';
			echo '</tr>';
			$k = 1 - $k;
			}
		?>
		</table>
	</div>

	</form>
	<?php
}
}